﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ViewModels
{
    /// <summary>
    /// 借阅信息视图模型
    /// </summary>
    public class BorrowVM
    {
        public Guid BorrowID { get; set; }
        public string BookID { get; set; }
        public Guid UserID { get; set; }
        public DateTime BorrowDate { get; set; }
        public DateTime ReturnDate { get; set; }
        public bool isReturned { get; set; }
        public string ReturnString { get; set; }
        public BookVM BookVM { get; set; }
        public UserVM UserVM { get; set; }
        public BorrowVM()
        {
            this.BorrowID
                = this.UserID
                = Guid.NewGuid();
            this.BorrowDate = DateTime.Now;
            this.isReturned = false;
            if (this.isReturned)
                ReturnString = "已归还";
            else
                ReturnString = "待归还";
        }
        public BorrowVM(BorrowVM vm)
        {
            this.BorrowID = vm.BorrowID;
            this.BorrowDate = vm.BorrowDate;
            this.ReturnDate = vm.ReturnDate;
            this.isReturned = vm.isReturned;
            if (this.isReturned)
                ReturnString = "已归还";
            else
                ReturnString = "待归还";
            if (vm.BookVM != null)
            {
                this.BookVM.BookID = vm.BookVM.BookID;
                this.BookVM.BookName = vm.BookVM.BookName;
                this.BookVM.ISBN = vm.BookVM.ISBN;
                this.BookVM.Author = vm.BookVM.Author;
                this.BookVM.PublishDate = vm.BookVM.PublishDate;
                this.BookVM.BookVersion = vm.BookVM.BookVersion;
                this.BookVM.WordCount = vm.BookVM.WordCount;
                this.BookVM.PageCount = vm.BookVM.PageCount;
                this.BookVM.Publisher = vm.BookVM.Publisher;
                this.BookVM.Price = vm.BookVM.Price;                
            }
            if(vm.UserVM!=null)
            {
                this.UserVM.UserID = vm.UserID;
                this.UserVM.UserName = vm.UserVM.UserName;
                this.UserVM.StuNo = vm.UserVM.StuNo;
                this.UserVM.Name = vm.UserVM.Name;
                this.UserVM.Gender = vm.UserVM.Gender;
                if (this.UserVM.Gender)
                    this.UserVM.GenderString = "男";
                else
                    this.UserVM.GenderString = "女";
                this.UserVM.IDNumber = vm.UserVM.IDNumber;
                this.UserVM.CreateDate = vm.UserVM.CreateDate;
                this.UserVM.Email = vm.UserVM.Email;
                this.UserVM.Mobile = vm.UserVM.Mobile;
                this.UserVM.Address = vm.UserVM.Address;
                this.UserVM.URL = vm.UserVM.URL;
                this.UserVM.UserPassword = vm.UserVM.UserPassword;
                this.UserVM.RoleID = vm.UserVM.RoleID;
                this.UserVM.RoleName = vm.UserVM.RoleName;
                this.UserVM.ClassID = vm.UserVM.ClassID;
                this.UserVM.ClassName = vm.UserVM.ClassName;
            }
        }
    }
}
